package com.itheima.service.impl;

import com.itheima.dao.WebConfigDao;
import com.itheima.pojo.WebConfig;
import com.itheima.service.WebConfigService;
import com.itheima.vo.WebConfigVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;


@Service
public class WebConfigServiceImpl implements WebConfigService {

    @Autowired
    private WebConfigDao webConfigDao;

    /**
     * 修改网站配置
     *
     * @param webConfigVO
     *  @return void
     *@author itheima
     */
    @Override
    public int edit(WebConfigVO webConfigVO) {
        WebConfig webConfig = new WebConfig();
        webConfig.setAliPay(webConfigVO.getAliPay());
        webConfig.setAuthor(webConfigVO.getAuthor());
        webConfig.setGitee(webConfigVO.getGitee());
        webConfig.setGithub(webConfigVO.getGithub());
        webConfig.setKeyword(webConfigVO.getKeyword());
        webConfig.setLoginTypeList(webConfigVO.getLoginTypeList());
        webConfig.setLogo(webConfigVO.getLogo());
        webConfig.setName(webConfigVO.getName());
        webConfig.setWeixinPay(webConfigVO.getWeixinPay());
        webConfig.setWeChat(webConfigVO.getWeChat());
        webConfig.setQqNumber(webConfigVO.getQqNumber());
        webConfig.setStartComment(webConfigVO.getStartComment());
        webConfig.setUid(webConfigVO.getUid());
        webConfig.setSummary(webConfigVO.getSummary());
        webConfig.setRecordNum(webConfigVO.getRecordNum());

        int count = webConfigDao.updateByPrimaryKey(webConfig);

        return count;
    }

    /**
     * 获取其网站配置
     *@param
     * @return void
     *@author itheima
     */
    @Override
    public List<WebConfig> getWebConfig() {
        WebConfig webConfig = new WebConfig();
        List<WebConfig> configList = webConfigDao.selectByExample(new Example(webConfig.getClass()));
        return configList;
    }
}
